package cn.hp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.hp.domain.Order;
import cn.hp.domain.Product;
import cn.hp.service.OrderService;
import cn.hp.service.ProductService;

@Controller
@RequestMapping("/order")
public class OrderController {
	@Autowired
	private OrderService orderService;
	
	@Autowired
	private ProductService productService;
	
	
	
	
	
	
	
	
	
	
	
	
	//全查
	@RequestMapping("/findAll")
	public ModelAndView findAll(){
		List<Order> orderList=orderService.findAll();
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("orderList", orderList);
		modelAndView.setViewName("order-list");
		return modelAndView;
		
	}
	
	//查询所有的产品信息 ,数据回显
	@RequestMapping("/addUI")
	public ModelAndView addUI(){
		List<Product> pList = productService.findAll();
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("pList", pList);
		modelAndView.setViewName("order-add"); 
		return modelAndView;
	}
	
	
	
	//添加
	@RequestMapping("/save")
	public String save(Order order){
		orderService.save(order);
		return "redirect:findAll";
	}
	
	
}
